package com.sjb.sixteen_journey_backend.controller;


import com.sjb.sixteen_journey_backend.common.R;
import com.sjb.sixteen_journey_backend.entity.MyTime;
import com.sjb.sixteen_journey_backend.service.IMyTimeService;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * 我的此刻表
 *
 * @author jcz
 * @since 2024-07-12
 */
@RestController
@RequestMapping("/my-time")
public class MyTimeController {
    @Autowired
    private IMyTimeService myTimeService;

    /**
     * 添加一篇'我的此刻'
     *
     * @param myTime
     * @return
     */
    @PostMapping("/addMyTime")
    public R addMyTime(@RequestBody @Valid MyTime myTime) {
        return myTimeService.addMyTime(myTime);
    }
//    @PostMapping("/addMyTime")
//    public R addMyTime(@RequestBody MyTime myTime, @RequestParam("image") ArrayList<MultipartFile> image) throws IOException {
//        return myTimeService.addMyTime(myTime, image);
//    }

    /**
     * 获取所有'我的此刻'
     *
     * @return
     */
    @GetMapping("/getAllMyTime")
    public R<List<MyTime>> getAllMyTime() {
        return myTimeService.getAllMyTime();
    }


    /**
     * 根据'我的此刻'id获取
     *
     * @param id 当前'我的此刻'的id
     * @return
     */
    @GetMapping("/getMyTimeById/{id}")
    public R<MyTime> getMyTimeById(@PathVariable("id") Integer id) {
        return myTimeService.getMyTimeById(id,true);
    }



    /**
     * 获取登录用户的所有'我的此刻'
     *
     * @return
     */
    @GetMapping("/getAllMyTimeByUserId")
    public R<List<MyTime>> getAllMyTimeByUserId() {
        return myTimeService.getAllMyTimeByUserId();
    }

    /**
     * 获取某用户的所有'我的此刻'
     * @param id 用户id
     * @return
     */
    @GetMapping("/getMyTimeByAnyUserId/{id}")
    public R<List<MyTime>> getMyTimeByAnyUserId(@PathVariable("id") Integer id) {
        return myTimeService.getMyTimeByAnyUserId(id);
    }

    /**
     * 删除用户的一篇'我的此刻'
     * @param id '我的此刻'的id
     * @return
     */
    @DeleteMapping("/deleteMyTimeById/{id}")
    public R deleteMyTimeById(@PathVariable("id") Integer id ) {
        return myTimeService.deleteMyTimeById(id);
    }

    /**
     * 相关此刻
     * @param site 地点
     * @return
     */
    @GetMapping("/getOtherMyTime")
    public R<List<MyTime>> getOtherMyTime(@RequestParam("site") String site) {
        return myTimeService.getOtherMyTime(site);
    }
}
